﻿Imports System.Data.OleDb

Public Class UserProfile
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If (Not IsPostBack) Then
            BindGender()
            BindUserProfile()
        End If
    End Sub

    Private Sub BindGender()
        Dim dsRole = DataAccessLayer.ExecuteDataSet("Select * from  Gender")
        ddlGender.DataSource = dsRole
        ddlGender.DataTextField = "Gender"
        ddlGender.DataValueField = "ID"
        ddlGender.DataBind()
        ddlGender.Items.Insert(0, New ListItem("Select", "0"))
    End Sub

    Private Sub BindUserProfile()

        Dim p1 As New OleDbParameter("@f1", Request.QueryString("ID"))
        Using oledbReader As OleDbDataReader = DataAccessLayer.ExecuteDataReader("Select * from UserProfile where username= @f1", p1)
            While oledbReader.Read
                If Not IsDBNull(oledbReader.Item(1)) Then
                    txtFirstName.Text = oledbReader.Item(1)
                End If
                If Not IsDBNull(oledbReader.Item(2)) Then
                    txtLastName.Text = oledbReader.Item(2)
                End If

                If Not IsDBNull(oledbReader.Item(3)) Then
                    ddlGender.SelectedValue = oledbReader.Item(3)
                End If

                If Not IsDBNull(oledbReader.Item(4)) Then
                    userProfileImage.ImageUrl = oledbReader.Item(4)
                Else
                    userProfileImage.Visible = False
                End If

                If Not IsDBNull(oledbReader.Item(5)) Then
                    txtDateOFBirth.Text = oledbReader.Item(5)
                End If
                If Not IsDBNull(oledbReader.Item(10)) Then
                    If oledbReader.Item(10) = "True" Then
                        cbEmailSubscription.Checked = True
                    Else
                        cbEmailSubscription.Checked = False
                    End If
                End If
            End While
            oledbReader.Close()
        End Using
    End Sub

End Class